<?php

/**
 * Description of ArbalanceController
 *
 * @author Khanh Nam
 * @email nam.trankhanh.vn@gmail.com
 */
class ArbalanceController extends Controller{
    //put your code here
    /**
     * @return array action filters
     */
    public function filters() {
        return array(
            'accessControl', // perform access control for CRUD operations
            array(
                'application.filters.RequireLoginFilter',
            ),
        );
    }

    /**
     * Specifies the access control rules.
     * This method is used by the 'accessControl' filter.
     * @return array access control rules
     */
    public function accessRules() {
        return array(
            array('allow', // allow all users to perform 'index' and 'view' actions
             
               'users'=>array('@'),
            ),
         
            array('deny', // deny all users
                'users' => array('*'),
            ),
        );
    }
    public function actionIndex(){
        $this->render('index');
    }
    public function actionList($sort=NULL,$page=0){
        if ($page > 0)
            $page--;
        $order = CJSON::decode($sort);

        $crit = new CDbCriteria();
        $crit->addCondition('depositdate is NULL');
//            if($query!=NULL){
//                
//            }
        $crit->order = isset($order) ? $order[0]['property'] . ' ' . $order[0]['direction'] : NULL;
        $data = new CActiveDataProvider('RecLed', array(
                    'criteria' => $crit,
                    'pagination' => array(
                        'pageSize' => 20,
                        'currentPage' => $page
                    )
                ));

        if ($data != NULL && count($data->getData()) > 0) {
            $rs = array();
            $rs['totalCount'] = $data->getTotalItemCount();
            foreach ($data->getData() as $i => $item) {
                /* var Warehouse $item */
                $rs['data'][$i] = $item->getAttributes();
                $rs['data'][$i]['customer'] = $item->customer->lastname;
                $rs['data'][$i]['paymethodtext'] = PaymentMethods::getDesc($item->paymethod);
            }
            echo json_encode($rs);
        }
        Yii::app()->end();
    }
}

?>
